<?
session_start();
$sender_id = $_REQUEST['sender_id'];

include('./../config/db_settings.php');
include('pms_inc.php');

$user = $_SESSION[$settings['session_prefix'].'user_id'];

if($sender_id>0 && $sender_id == $user){
	header("Location:sent.php");
}else{
	header("Location:inbox.php");
}

//Are they logged in or not?
if(!$user)
{
}
else
{
    //check the msg_id variable from the URL.
    $msg_id = $_REQUEST['msg_id'];
    
    if($msg_id>0)
    {
        if($sender_id>0 && $sender_id == $user){
        	//delete the msg by sender: received+2
        	mysql_query("update ".$db_settings['messages_table']." set received=received+2 WHERE id='$msg_id' AND sender_id='$user'");
        }
        else{
        	//delete the msg by receiver: received+4
        	mysql_query("update ".$db_settings['messages_table']." set received=received+4 WHERE id='$msg_id' AND receiver_id='$user'");
        }
    }
    else
    {
        //A foreach loop for each pm in the array, get the values and set it as $pm_id because they were the ones selected for deletion
        foreach($_POST['pms'] as $num => $pm_id)
        	{
	        	if($sender_id>0 && $sender_id == $user){
		        	//delete the msg by sender: received+2
		        	mysql_query("update ".$db_settings['messages_table']." set received=received+2 WHERE id='$pm_id' AND sender_id='$user'");
		        }
		        else{
		        	//delete the msg by receiver: received+4
		        	mysql_query("update ".$db_settings['messages_table']." set received=received+4 WHERE id='$pm_id' AND receiver_id='$user'");
		        }        	
        	}
    }
}
?> 